package com.dyw.Day13;


/**
 * @author Devil
 * @create 2022-01-22-23:34
 *
 * 反转链表
 *
 * 思路: 顺序遍历原链表 再用尾插法创建一个新链表
 */
@SuppressWarnings("all")
public class Demo01 {
    public ListNode reverseList(ListNode head) {
        //创建一个空结点
        ListNode Head = new ListNode(0,null);
        ListNode p = head;
        while(p!=null){
            ListNode node = new ListNode(p.val, Head.next);
            Head.next = node;
            p = p.next;
        }
        return Head.next;
    }
}